package com.wanxx.controller;

import com.wanxx.domain.Student;
import com.wanxx.exception.AgeException;
import com.wanxx.exception.MyException;
import com.wanxx.exception.NameException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;


@Controller
public class MyController {

    @RequestMapping(value = "/register.do")
    public ModelAndView doRegister(Student student) throws MyException {
        ModelAndView mv = new ModelAndView();
        if (student.getName().length() > 4) {
            throw new NameException("姓名太长");
        }
        if (student.getAge() < 0 || student.getAge() > 150) {
            throw new AgeException("年龄错误");
        }
        mv.addObject("name", student.getName());
        mv.addObject("age", student.getAge());
        mv.setViewName("show");
        return mv;
    }


}
